// pages/user/reportList/reportList.js
var app = getApp();
var load= true;
Page({
  /**
   * 页面的初始数据
   */
  data: {
    hasMore: false,
    loading: false,
    page: 1,
    pagesize: 20,
    reportList: [],
    load_show:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getReport();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    if (!that.data.hasMore) {
      return false;
    }
    that.data.page++;
    that.setData({
      loading: true
    })
    that.getReport();
  },


  // 获取邀请列表
  getReport() {
    var that = this;
    app.ajax({
      url: 'User/Spread/reportList',
      method: "POST",
      data: {
        page: that.data.page,
        row: that.data.pagesize,
      },
      success: function (res) {
        if (res.data.code == 1000) {
          if (that.data.page == 1) {
            that.setData({
              reportList: res.data.data.data
            })
          } else {
            that.setData({
              reportList: that.data.reportList.concat(res.data.data.data)
            })
          }
          // 是否加载更多
          var hasMore = true;
          if (res.data.data.data.length < that.data.pagesize) {
            hasMore = false;
          }
          that.setData({
            hasMore: hasMore,
            loading: false,
            load_show:true
          });
          load= false;
        } else {
          if (that.data.page == 1) {
            that.setData({
              hasMore: false,
              loading: false
            })
          } else {
            that.setData({
              hasMore: false,
              loading: false
            })
          }
        }
      }
    })
  },

  // 我要报备
  myReport(){
    wx.navigateTo({
      url: '../myReport/myReport',
    })
  }
})